﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Zeta;
using Zeta.Common;
using Zeta.CommonBot;
using Zeta.Internals.Actors;
using Zeta.Internals.SNO;

namespace SarkothFarmer.Helpers
{
    class Composites
    {
        public static bool IsUnitNear(int yards)
        {
            return Objects.Units.Any(x => x.Distance <= yards);
        }

        public static bool IsNear(Vector3 v)
        {
            return ZetaDia.Me.Position.Distance(v) <= 10;
        }

        public static bool HasPower(SNOPower power)
        {
            if (ZetaDia.Me.GetHotbarPowerId(HotbarSlot.HotbarSlot1) == power)
                return true;
            if (ZetaDia.Me.GetHotbarPowerId(HotbarSlot.HotbarSlot2) == power)
                return true;
            if (ZetaDia.Me.GetHotbarPowerId(HotbarSlot.HotbarSlot3) == power)
                return true;
            if (ZetaDia.Me.GetHotbarPowerId(HotbarSlot.HotbarSlot4) == power)
                return true;
            if (ZetaDia.Me.GetHotbarPowerId(HotbarSlot.HotbarMouseLeft) == power)
                return true;
            return ZetaDia.Me.GetHotbarPowerId(HotbarSlot.HotbarMouseRight) == power;
        }
        public static Vector3 VectorWithDistanceFrom(Vector3 v, float yards)
        {
            var distance = ZetaDia.Me.Position.Distance(v);
            if (distance <= yards)
                return VectorWithDistanceFrom(v, distance - 1);
            var difX = v.X - ZetaDia.Me.Position.X;
            var difY = v.Y - ZetaDia.Me.Position.Y;
            var difZ = v.Z - ZetaDia.Me.Position.Z;
            var factor = (distance - yards) / distance;
            var newX = ZetaDia.Me.Position.X + factor * difX;
            var newY = ZetaDia.Me.Position.Y + factor * difY;
            var newZ = ZetaDia.Me.Position.Z + factor * difZ;
            return new Vector3(newX, newY, newZ);
        }
        public static float PickupRange
        {
            get { return ZetaDia.Me.GoldPickupRadius; }
        }
        public static float LootRadius
        {
            get { return Zeta.CommonBot.Settings.CharacterSettings.Instance.LootRadius; }
            set { Zeta.CommonBot.Settings.CharacterSettings.Instance.LootRadius = value; }
        }
        public static float KillRadius
        {
            get { return Zeta.CommonBot.Settings.CharacterSettings.Instance.KillRadius; }
            set { Zeta.CommonBot.Settings.CharacterSettings.Instance.KillRadius = value; }
        }
        public static bool PickupLoot
        {
            get { return ProfileManager.CurrentProfile.PickupLoot; }
            set { ProfileManager.CurrentProfile.PickupLoot = value; }
        }
        public static bool KillMonsters
        {
            get { return ProfileManager.CurrentProfile.KillMonsters; }
            set { ProfileManager.CurrentProfile.KillMonsters = value; }
        }
        public static bool IsCleared
        {
            get { return Objects.Gold.FirstOrDefault() == null && Objects.Loots.FirstOrDefault() == null && Objects.Units.FirstOrDefault() == null; }
        }
        public static bool InCellar
        {
            get { return ZetaDia.Me.WorldDynamicId == 1999568897; }
        }
    }
}